package com.br4mmie.asciistory.battle;

import java.util.ArrayList;

import com.br4mmie.asciistory.mission.Item;


/**
 * @author Niels
 * Describes a drop item that can drop in battle.
 * Contains an item, the chance to drop it and the maximum amount of the item to drop
 */
public class BattleDrop 
{
	private int chance;//Chance for the item to drop
	private int maxAmount;//maximum amount of this item to drop
	private Item item;//item to drop
	
	/**
	 * 
	 * @param chance chance for the item to drop
	 * @param amount maximum amount to drop
	 * @param item type of item to drop
	 */
	BattleDrop(int chance, int amount, Item item)
	{
		this.chance = chance;
		maxAmount = amount;
		this.item = item;
	}
	
	/**
	 * Adds dropped items to the given list if the passed int is higher than the chancefactor required 
	 * @param list List to add items to
	 * @param randomVal Value passed, items added if higher than required value
	 */
	public void getDrops(ArrayList<Item> list, int randomVal)
	{
		if (randomVal < chance) return;
		int amount = (int)((Math.random()*maxAmount)+1);
		for (int i=0; i<amount; i++)
		{
			list.add(item);
		}
	}
}
